<template>
    <body id="paper">
    <el-form :model="loginForm" :rules="rules" class="login-container" label-position="left"
             label-width="0px" v-loading="loading">
        <h3 class="login_title">系统登录</h3>
        <el-form-item prop='mobile'>
            <label>手机号码</label>
            <div class="control-group form-phone-fill">
                <div class="btn-group"style="margin-right: 10px">
                <button class="btn btn-default dropdown-toggle">
                    <span class="js-txt dropdown-value">中国+86</span>
                    <span class="caret"></span>
                </button>
                </div>
                <input type="text" placeholder="请输入手机号码" v-model="loginForm.mobile"></input>
            </div>
            </el-form-item>
            <el-form-item prop='code'>
            <div class="form-group">
                <label class="control-label">验证码</label>
                <div class="btn-group phone-code">
                    <div class="control-group">
                        <input type="text" placeholder="请输入验证码" v-model="loginForm.code"></input>
                    </div>
                    <span class="input-group-btn">
                        <button class="btn" style="background:#505458;color: white" v-on:click="captcha">获取验证码</button>
                    </span>
                </div>
            </div>
        </el-form-item>
        <el-form-item style="width: 100%">
            <el-button type="primary" style="width: 100%;background: #505458;border: none" v-on:click="login">立即登录</el-button>
        </el-form-item>
    </el-form>
    </body>
</template>
<script>
    import inde from "./admin/inde";

    export default{
        data () {
            return {
                rules: {
                    mobile: [{required: true, message: '手机号不能为空', trigger: 'blur'}],
                    code: [{required: true, message: '验证码不能为空', trigger: 'blur'}]
                },
                checked: true,
                loginForm: {
                    mobile: '',
                    code: ''
                },
                loading: false
            }
        },
        methods: {
            captcha(){
                var _this=this;
                this.$axios.post('/captcha',{
                    mobile: this.loginForm.mobile
                }).then(resp=>{

                })
            },
            login(){
                var _this=this
                this.$axios.post('auth',{
                    uaccount: this.loginForm.uAccount,
                    upwd:this.loginForm.uPwd
                }).then(resp=>{
                    if (resp.data.code===200){
                        _this.$router.replace('/index')
                        console.log(resp.data)
                    }
                    else {
                        _this.$alert(resp.data.message, '提示', {
                            confirmButtonText: '确定'
                        })
                    }
                })
            },

            login1 () {
                var _this = this
                this.$axios
                    .post('/login', {
                        uAccount: this.loginForm.uAccount,
                        uPwd: this.loginForm.uPwd
                    })
                    .then(resp => {
                        if (resp.data.code === 200) {
                            var role=resp.data.result.identity
                            if (role=="user"){
                                var data = resp.data.result.uName
                                _this.$store.commit('login', data)
                                console.log(data)
                                var path = _this.$route.query.redirect
                                _this.$router.replace({path: path === '/' || path === undefined ? '/index' : path})
                            }
                            else {
                                _this.$router.push({path:'/findRz'})
                            }
                        } else {
                            this.$alert(resp.data.message, '提示', {
                                confirmButtonText: '确定'
                            })
                        }
                    })
                    .catch(failResponse => {})
            }
        }
    }
</script>
<style>
    .input-group-btn>.btn {
        border-bottom-left-radius: 0;
        border-top-left-radius: 0;
        margin-left: -3px;
        padding: 0 15px;
        height: 40px;
        line-height: 40px;
    }
    input{
        border: 1px solid #ddd;
        color: #34495e;
        left: 10px;
        font-size: 14px;
        width: 166px;
        padding: 0px 0px 0px 10px;
        border-radius: 3px;
        outline: 0;
    }
    .caret {
        font-family: FontAwesome;
        position: absolute;
        right: 10px;
        top: 8px;
        font-size: 18px;
        color: #666;
    }
    .form-phone-fill .btn-group .dropdown-toggle {
        min-width: auto;
    }
    .btn-group .dropdown-toggle {
        background: #fff;
        border: 1px solid #ddd;
        border-radius: 3px;
        color: #333;
        padding: 10px 25px 10px 10px;
        text-align: left;
        position: relative;
        font-size: 14px;
        min-width: 160px;
        min-width: 128px\9;
        vertical-align: top;
        width: 100%;
        outline: 0;
    }
    .login-tips a{
        color: #67cab2;
    }
    #paper {
        background:url("../assets/img/bg/eva1.jpg") no-repeat;
        background-position: center;
        height: 100%;
        width: 100%;
        background-size: cover;
        position: fixed;
    }
    body{
        margin: 0;
    }
    .login-container {
        border-radius: 15px;
        background-clip: padding-box;
        margin: 90px auto;
        width: 350px;
        padding: 35px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;
    }
    .login_title {
        margin: 0px auto 40px auto;
        text-align: center;
        color: #505458;
    }
    .login_remember {
        margin: 0px 0px 35px 0px;
        text-align: left;
    }
</style>
